#pragma once
/*
 * This file is intended to serialize custom structs into data stream, and unserialize back to structs.
 *
 * Usage:
 *    Inside the struct or class,   RN_PACK(Class, member1, member2, ...)
 *    If the struct has customed type member, make sure the nested member structs are intruded by RN_PACK.
 *
 * Author: Feng Liang, 201.
 *
*/
#include <QDataStream>
#define STREAM_O <<
#define STREAM_I >>
#define RN_PACK_EXPAND(...) __VA_ARGS__

#define RN_PACK_COUNT(LEVEL, _99,_98,_97,_96,_95,_94,_93,_92,_91,_90,_89,_88,_87,_86,_85,_84,_83,_82,_81,_80,\
                            _79,_78,_77,_76,_75,_74,_73,_72,_71,_70,_69,_68,_67,_66,_65,_64,_63,_62,_61,_60,\
                            _59,_58,_57,_56,_55,_54,_53,_52,_51,_50,_49,_48,_47,_46,_45,_44,_43,_42,_41,_40,\
                            _39,_38,_37,_36,_35,_34,_33,_32,_31,_30,_29,_28,_27,_26,_25,_24,_23,_22,_21,_20,\
                            _19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...)\
                            LEVEL##N

#define RN_PACK(ACTION, ...)   RN_PACK_N(NSTREAM, ACTION, __VA_ARGS__)
#define NSTREAM_DEF(ACTION, A)       ACTION d.A

#ifndef _MSC_VER
#define RN_PACK_N(LEVEL,ACTION, ...)  \
        RN_PACK_COUNT(LEVEL, __VA_ARGS__,\
                            _99,_98,_97,_96,_95,_94,_93,_92,_91,_90,_89,_88,_87,_86,_85,_84,_83,_82,_81,_80,\
                            _79,_78,_77,_76,_75,_74,_73,_72,_71,_70,_69,_68,_67,_66,_65,_64,_63,_62,_61,_60,\
                            _59,_58,_57,_56,_55,_54,_53,_52,_51,_50,_49,_48,_47,_46,_45,_44,_43,_42,_41,_40,\
                            _39,_38,_37,_36,_35,_34,_33,_32,_31,_30,_29,_28,_27,_26,_25,_24,_23,_22,_21,_20,\
                            _19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1)(ACTION, __VA_ARGS__)

#define NSTREAM_1(ACTION,  A)        NSTREAM_DEF(ACTION, A)
#define NSTREAM_2(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_1(ACTION, __VA_ARGS__)
#define NSTREAM_3(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_2(ACTION, __VA_ARGS__)
#define NSTREAM_4(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_3(ACTION, __VA_ARGS__)
#define NSTREAM_5(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_4(ACTION, __VA_ARGS__)
#define NSTREAM_6(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_5(ACTION, __VA_ARGS__)
#define NSTREAM_7(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_6(ACTION, __VA_ARGS__)
#define NSTREAM_8(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_7(ACTION, __VA_ARGS__)
#define NSTREAM_9(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_8(ACTION, __VA_ARGS__)
#define NSTREAM_10(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_9(ACTION, __VA_ARGS__)
#define NSTREAM_11(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_10(ACTION, __VA_ARGS__)
#define NSTREAM_12(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_11(ACTION, __VA_ARGS__)
#define NSTREAM_13(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_12(ACTION, __VA_ARGS__)
#define NSTREAM_14(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_13(ACTION, __VA_ARGS__)
#define NSTREAM_15(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_14(ACTION, __VA_ARGS__)
#define NSTREAM_16(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_15(ACTION, __VA_ARGS__)
#define NSTREAM_17(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_16(ACTION, __VA_ARGS__)
#define NSTREAM_18(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_17(ACTION, __VA_ARGS__)
#define NSTREAM_19(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_18(ACTION, __VA_ARGS__)
#define NSTREAM_20(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_19(ACTION, __VA_ARGS__)
#define NSTREAM_21(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_20(ACTION, __VA_ARGS__)
#define NSTREAM_22(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_21(ACTION, __VA_ARGS__)
#define NSTREAM_23(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_22(ACTION, __VA_ARGS__)
#define NSTREAM_24(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_23(ACTION, __VA_ARGS__)
#define NSTREAM_25(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_24(ACTION, __VA_ARGS__)
#define NSTREAM_26(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_25(ACTION, __VA_ARGS__)
#define NSTREAM_27(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_26(ACTION, __VA_ARGS__)
#define NSTREAM_28(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_27(ACTION, __VA_ARGS__)
#define NSTREAM_29(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_28(ACTION, __VA_ARGS__)
#define NSTREAM_30(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_29(ACTION, __VA_ARGS__)
#define NSTREAM_31(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_30(ACTION, __VA_ARGS__)
#define NSTREAM_32(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_31(ACTION, __VA_ARGS__)
#define NSTREAM_33(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_32(ACTION, __VA_ARGS__)
#define NSTREAM_34(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_33(ACTION, __VA_ARGS__)
#define NSTREAM_35(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_34(ACTION, __VA_ARGS__)
#define NSTREAM_36(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_35(ACTION, __VA_ARGS__)
#define NSTREAM_37(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_36(ACTION, __VA_ARGS__)
#define NSTREAM_38(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_37(ACTION, __VA_ARGS__)
#define NSTREAM_39(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_38(ACTION, __VA_ARGS__)
#define NSTREAM_40(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_39(ACTION, __VA_ARGS__)
#define NSTREAM_41(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_40(ACTION, __VA_ARGS__)
#define NSTREAM_42(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_41(ACTION, __VA_ARGS__)
#define NSTREAM_43(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_42(ACTION, __VA_ARGS__)
#define NSTREAM_44(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_43(ACTION, __VA_ARGS__)
#define NSTREAM_45(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_44(ACTION, __VA_ARGS__)
#define NSTREAM_46(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_45(ACTION, __VA_ARGS__)
#define NSTREAM_47(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_46(ACTION, __VA_ARGS__)
#define NSTREAM_48(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_47(ACTION, __VA_ARGS__)
#define NSTREAM_49(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_48(ACTION, __VA_ARGS__)
#define NSTREAM_50(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_49(ACTION, __VA_ARGS__)
#define NSTREAM_51(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_50(ACTION, __VA_ARGS__)
#define NSTREAM_52(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_51(ACTION, __VA_ARGS__)
#define NSTREAM_53(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_52(ACTION, __VA_ARGS__)
#define NSTREAM_54(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_53(ACTION, __VA_ARGS__)
#define NSTREAM_55(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_54(ACTION, __VA_ARGS__)
#define NSTREAM_56(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_55(ACTION, __VA_ARGS__)
#define NSTREAM_57(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_56(ACTION, __VA_ARGS__)
#define NSTREAM_58(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_57(ACTION, __VA_ARGS__)
#define NSTREAM_59(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_58(ACTION, __VA_ARGS__)
#define NSTREAM_60(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_59(ACTION, __VA_ARGS__)
#define NSTREAM_61(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_60(ACTION, __VA_ARGS__)
#define NSTREAM_62(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_61(ACTION, __VA_ARGS__)
#define NSTREAM_63(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_62(ACTION, __VA_ARGS__)
#define NSTREAM_64(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_63(ACTION, __VA_ARGS__)
#define NSTREAM_65(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_64(ACTION, __VA_ARGS__)
#define NSTREAM_66(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_65(ACTION, __VA_ARGS__)
#define NSTREAM_67(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_66(ACTION, __VA_ARGS__)
#define NSTREAM_68(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_67(ACTION, __VA_ARGS__)
#define NSTREAM_69(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_68(ACTION, __VA_ARGS__)
#define NSTREAM_70(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_69(ACTION, __VA_ARGS__)
#define NSTREAM_71(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_70(ACTION, __VA_ARGS__)
#define NSTREAM_72(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_71(ACTION, __VA_ARGS__)
#define NSTREAM_73(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_72(ACTION, __VA_ARGS__)
#define NSTREAM_74(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_73(ACTION, __VA_ARGS__)
#define NSTREAM_75(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_74(ACTION, __VA_ARGS__)
#define NSTREAM_76(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_75(ACTION, __VA_ARGS__)
#define NSTREAM_77(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_76(ACTION, __VA_ARGS__)
#define NSTREAM_78(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_77(ACTION, __VA_ARGS__)
#define NSTREAM_79(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_78(ACTION, __VA_ARGS__)
#define NSTREAM_80(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_79(ACTION, __VA_ARGS__)
#define NSTREAM_81(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_80(ACTION, __VA_ARGS__)
#define NSTREAM_82(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_81(ACTION, __VA_ARGS__)
#define NSTREAM_83(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_82(ACTION, __VA_ARGS__)
#define NSTREAM_84(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_83(ACTION, __VA_ARGS__)
#define NSTREAM_85(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_84(ACTION, __VA_ARGS__)
#define NSTREAM_86(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_85(ACTION, __VA_ARGS__)
#define NSTREAM_87(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_86(ACTION, __VA_ARGS__)
#define NSTREAM_88(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_87(ACTION, __VA_ARGS__)
#define NSTREAM_89(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_88(ACTION, __VA_ARGS__)
#define NSTREAM_90(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_89(ACTION, __VA_ARGS__)
#define NSTREAM_91(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_90(ACTION, __VA_ARGS__)
#define NSTREAM_92(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_91(ACTION, __VA_ARGS__)
#define NSTREAM_93(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_92(ACTION, __VA_ARGS__)
#define NSTREAM_94(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_93(ACTION, __VA_ARGS__)
#define NSTREAM_95(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_94(ACTION, __VA_ARGS__)
#define NSTREAM_96(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_95(ACTION, __VA_ARGS__)
#define NSTREAM_97(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_96(ACTION, __VA_ARGS__)
#define NSTREAM_98(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_97(ACTION, __VA_ARGS__)
#define NSTREAM_99(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_98(ACTION, __VA_ARGS__)
#else
#define RN_PACK_N(LEVEL,ACTION, ...)  RN_PACK_EXPAND(\
        RN_PACK_COUNT(LEVEL, __VA_ARGS__,\
                            _99,_98,_97,_96,_95,_94,_93,_92,_91,_90,_89,_88,_87,_86,_85,_84,_83,_82,_81,_80,\
                            _79,_78,_77,_76,_75,_74,_73,_72,_71,_70,_69,_68,_67,_66,_65,_64,_63,_62,_61,_60,\
                            _59,_58,_57,_56,_55,_54,_53,_52,_51,_50,_49,_48,_47,_46,_45,_44,_43,_42,_41,_40,\
                            _39,_38,_37,_36,_35,_34,_33,_32,_31,_30,_29,_28,_27,_26,_25,_24,_23,_22,_21,_20,\
                            _19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1))RN_PACK_EXPAND((ACTION, __VA_ARGS__))

#define NSTREAM_1(ACTION,  A)        NSTREAM_DEF(ACTION, A)
#define NSTREAM_2(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_1 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_3(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_2 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_4(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_3 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_5(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_4 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_6(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_5 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_7(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_6 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_8(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_7 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_9(ACTION,  A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_8 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_10(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_9 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_11(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_10 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_12(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_11 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_13(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_12 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_14(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_13 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_15(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_14 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_16(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_15 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_17(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_16 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_18(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_17 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_19(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_18 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_20(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_19 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_21(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_20 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_22(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_21 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_23(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_22 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_24(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_23 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_25(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_24 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_26(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_25 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_27(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_26 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_28(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_27 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_29(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_28 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_30(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_29 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_31(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_30 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_32(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_31 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_33(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_32 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_34(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_33 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_35(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_34 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_36(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_35 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_37(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_36 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_38(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_37 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_39(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_38 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_40(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_39 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_41(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_40 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_42(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_41 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_43(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_42 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_44(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_43 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_45(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_44 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_46(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_45 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_47(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_46 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_48(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_47 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_49(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_48 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_50(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_49 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_51(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_50 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_52(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_51 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_53(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_52 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_54(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_53 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_55(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_54 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_56(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_55 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_57(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_56 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_58(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_57 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_59(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_58 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_60(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_59 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_61(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_60 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_62(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_61 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_63(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_62 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_64(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_63 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_65(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_64 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_66(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_65 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_67(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_66 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_68(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_67 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_69(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_68 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_70(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_69 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_71(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_70 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_72(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_71 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_73(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_72 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_74(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_73 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_75(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_74 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_76(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_75 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_77(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_76 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_78(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_77 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_79(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_78 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_80(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_79 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_81(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_80 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_82(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_81 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_83(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_82 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_84(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_83 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_85(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_84 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_86(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_85 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_87(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_86 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_88(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_87 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_89(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_88 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_90(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_89 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_91(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_90 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_92(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_91 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_93(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_92 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_94(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_93 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_95(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_94 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_96(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_95 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_97(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_96 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_98(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_97 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#define NSTREAM_99(ACTION, A, ...)	 NSTREAM_DEF(ACTION, A)  NSTREAM_98 RN_PACK_EXPAND((ACTION, __VA_ARGS__))
#endif

//template<typename... T>
//QDataStream &pack(QDataStream &ds, T... t)
//{
//    QByteArray data;
//    ds.setDevice(&data);
////    QDataStream ds(&data, QIODevice::WriteOnly);
//    std::initializer_list<int> {(ds<<t, 0)...};
//    return ds;
//}

#define RNPACK(T, ...)\
friend QDataStream& operator<< (QDataStream& stream, const T& d)\
{\
    stream RN_PACK_EXPAND(RN_PACK(STREAM_O, __VA_ARGS__));\
    return stream;\
}\
\
friend QDataStream& operator>> (QDataStream& stream, T& d)\
{\
    stream RN_PACK_EXPAND(RN_PACK(STREAM_I, __VA_ARGS__));\
    return stream;\
}\
QByteArray data() const\
{\
    QByteArray ba;\
    QDataStream ds(&ba, QIODevice::WriteOnly);\
    ds << *this;\
    return ba;\
}\
static T from(const QByteArray &ba)\
{\
    QDataStream ds(ba);\
    T t;\
    ds >> t;\
    return t;\
}\
void fromByte(const QByteArray &ba,T& t)\
{\
    QDataStream ds(ba);\
    ds >> t;\
}\
void toData(QByteArray& ba) const\
{\
    QDataStream ds(&ba, QIODevice::WriteOnly);\
    ds << *this;\
}
//T (const QByteArray &ba)\
//{\
//    QDataStream ds(ba);\
//    ds >> *this;\
//}
